﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Logic;
using Helper;
using DBAccess;
using WHUT;

public partial class tokenTeam_works : System.Web.UI.Page
{
    IPagedDataProvider pdp = PagedDataProviderFactory.Instance();
    private const string TITLE = "拓垦作品";
    protected string introduce = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        pdp.ConnectionName = Common.GetDefaultSqlConnectionName();
        pdp.TableOrView = "t_token_work";
        pdp.FieldsToReturn = "name,style,date_add,tool,url,pic_img";
        pdp.FieldToOrder = "date_add";
        pdp.Ascending = false;
        pdp.PageSize = spPager.PageSize;
        pdp.RecordsFilter = "(1=1)";

        if (!IsPostBack)
        {
            BindWorks(true);
            BindIntr();
        }
    }

    private void BindWorks(bool bResetPager)
    {
        if (bResetPager)
        {
            spPager.CurrentPageIndex = 1;
            spPager.RecordsCount = pdp.TotalRecords;
        }
        // the current page
        pdp.CurrentPageIndex = spPager.CurrentPageIndex;
        rptWorks.DataSource = pdp.GetCurrentPageAsDataTable().DefaultView;
        rptWorks.DataBind();
    }

    /// <summary>
    /// 翻页控制
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void SimplePager1_PageIndexChanging(object sender, wbh.PageChangingEvent e)
    {
        spPager.CurrentPageIndex = e.NewIndex;
        BindWorks(false);
    }

    protected string GetPhotoPath(string fName)
    {
        return "/work/token/webImgs/" + fName;
    }

    private void BindIntr()
    {
        Introduce into = (new Introduce()).LoadByTags(TITLE);
        introduce = into.Content;
    }
}
